// 类：代表着拥有一些共同属性和方法的对象，统称为一个类
// 类是通过class声明的

class People {
    name: string//这里声明的属性就是实例对象身上的属性
    age: number
    constructor(name:string,age:number){
        // 构造了实例对象拥有哪些属性     在构造函数中使用this代表该类的实例对象
        this.name = name
        this.age = age
    }
    say():void{
        console.log('我会说话');
        
    }
}

var p1 = new People('张三',18)
console.log(p1.name);
p1.say()

class Animal {
    name:string
    constructor(name:string){
        this.name = name
    }
    say():string{
        return 'wo hui shuo hua'
    }
}
const p2 = new Animal('李')
console.log(p2.name);

console.log(p2.say());

// 类的继承  获取父类的所有属性和方法
class Man extends People{
    private huzi:boolean
    protected money:boolean = true
    constructor(name:string,age:number,huzi:boolean){
        super(name,age)
        this.huzi=huzi
    }
    run(){
        console.log(this.huzi,this.money);
        
    }
}
var m1 = new Man('孟庆明',20,false)
console.log(m1.name);

// 类的访问修饰符，默认是public代表类和实例都能访问
class Coder extends Man {
    static overTime:boolean = true//所有的程序员都经常加班
    private lazy: boolean = true//成员变量
    public hair: string = '头发很多'
    coding():void{
        console.log('我会搬砖');
    }
    getMoney():boolean {
        return this.money
    }
    setLazy(flag:boolean): void{
        this.lazy = flag
    }
    getLazy():boolean {
        return this.lazy
    }
}
var c = new Coder('庆明',18,false)
console.log(c.getMoney());
console.log(Coder.overTime);//静态属性和方法，类天生就具有的属性和方法，不需要实例化，可以直接访问


